<?php

namespace app\admin\model;
use houdunwang\arr\Arr;
use \think\Model;
class Article extends Model
{

//    public function getarticle()
//    {
//        return $this->select();
//    }

    //   无限极分类
    public function getarticle()
    {
//        获取所有分类数据
        $res = new Cate();
        $cateres = $res->select();
        return $this->sort($cateres);
    }
    public function sort($data,$pid=0,$level = 0){
        static $arr = array();
        foreach ($data as $k=>$v){
            if ($v['pid']==$pid){
                $v['level'] = $level;
                $arr[] = $v;
                $this->sort($data,$v['id'],$level+1);
            }
        }
        return $arr;
    }


//    删除时候的判断
    public function getchilredid($cateid){
        $cateres = $this->select();
        return $this->_getchilrenid($cateres,$cateid);
    }
    public function _getchilrenid($cateres,$cateid){
        static $arr = array();
        foreach ($cateres as $k=>$v){
            if ($v['pid'] ==$cateid){
                $arr[] = $v['id'];
                $this->_getchilrenid($cateres,$v['id']);
            }
        }
        return $arr;
    }





}
